﻿CREATE PROCEDURE [dbo].[state_s_Underwrite]
	@LoanID int
AS

DECLARE @DIR int
--SELECT @DIR = CASE WHEN OK >= 0 THEN 1 ELSE -1 END FROM v_PurchaseContract WHERE LoanID = @LoanID

SELECT @DIR = CASE COUNT(*) WHEN 0 THEN 1 ELSE -1 END
FROM t_Loan L CROSS APPLY Motobank_GL.dbo.ShowFaults(L.GLProgramID,@LoanID)
WHERE L.ID = @LoanID

EXEC state_Loan_Move @LoanID,@Dir

